package com.otp.webapp.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.appfuse.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.otp.model.test.template.Attribute;
import com.otp.model.test.template.AttributeSet;
import com.otp.service.instance.User1Manager;

/**
 * JSF Page class to handle reloading options in servlet context.
 *
 * @author Matt Raible
 */

@Component("mainMenu")
@Scope("session")
public class MainMenu extends BasePage implements Serializable {
    private static final long serialVersionUID = 2466200890766730676L;
    private User1Manager user1Manager;

	@Autowired
	public void setUser1Manager(@Qualifier("user1Manager") User1Manager user1Manager) {
		this.user1Manager = user1Manager;
	}
    
	public String getLoggedInUserId() {
		return getLoggedUser().getId()+"";
	}
	
	public boolean isDisplayDemo(){
		HttpServletRequest request = (HttpServletRequest) getFacesContext().getExternalContext().getRequest();
		User user = user1Manager.getUserByUsername(request.getRemoteUser());
		List<Attribute> attributes = new ArrayList<Attribute>();
		AttributeSet set = user.getOrgs().getAttSet();
		if(set==null) attributes=null;
		else attributes=set.getAtts();
		if(attributes==null||attributes.isEmpty()||(user.isDemoDone()!=null&&user.isDemoDone())) return false;
		else return true;

	}

    

}
